﻿using System.ComponentModel;
using System.Diagnostics;

namespace Microsoft.Office.PowerPoint.STAMP.Core
{
    /// <summary>
    /// Base class for ClosedCaption class.
    /// </summary>
    public abstract class ClosedCaptionBase : INotifyPropertyChanged
    {
        /// <summary>
        /// PropertyChanged event for INotifyPropertyChanged implementation.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Raises the PropertyChanged event.
        /// </summary>
        /// <param name="propertyName">The name of property that has a new value.</param>
        protected void OnPropertyChanged(string propertyName)
        {
            ConfirmPropertyName(propertyName);

            var handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        /// Debugging facility that ensures the property does exist on the class.
        /// </summary>
        /// <param name="propertyName"></param>
        [Conditional("Debug")]
        private void ConfirmPropertyName(string propertyName)
        {
            Debug.Assert(GetType().GetProperty(propertyName) != null, "Property " + propertyName + " is not a valid name.");
        }
    }
}